const { app } = require('electron')
const fs = require('fs')
const path = require('path')
const nuxtRun = require('@nuxt/cli').run
const isProd = app.isPackaged
const rootPath = isProd
  ? path.resolve(app.getAppPath(), '../../')
  : app.getAppPath()
const configPath = path.resolve(app.getAppPath(), 'nuxt.config.js')
const configRealPath = path.resolve(rootPath, 'nuxt.config.js')
if (!fs.existsSync(configRealPath)) {
  const config = fs.readFileSync(configPath)
  fs.writeFileSync(configRealPath, config)
}
module.exports = () => nuxtRun(isProd ? ['start'] : undefined)
